package com.alfred.mall.job.miaosha;

import com.alfred.mall.job.cache.GoodsRedisStoreCache;
import com.alfred.mall.miaosha.api.MiaoshaGoodsServcie;
import com.alfred.mall.miaosha.api.bo.MiaoshaGoodsBO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 秒杀商品库存定时触发入口
 */
@Component
public class MiaoshaTaskService {

    @Reference
    MiaoshaGoodsServcie miaoshaGoodsServcie;

    @Autowired
    GoodsRedisStoreCache goodsRedisStoreCache;

    /**
     * 每隔1分钟触发一次
     */
    @Scheduled(cron = "*/5 * * * * ?")
    public void doInit() {
        List<MiaoshaGoodsBO> listGoods = miaoshaGoodsServcie.selectAllMiaoshaGoods();
        for (MiaoshaGoodsBO goods : listGoods) {
            goodsRedisStoreCache.doInit(goods);
        }
    }
}
